package com.ziiwee.reduce.describe.creators.handlers;

import com.ziiwee.reduce.describe.FieldDescribe;
import com.ziiwee.reduce.describe.HttpRequestParameterType;
import com.ziiwee.reduce.describe.ResourceMethod;
import com.ziiwee.reduce.describe.models.FieldDescribeModel;
import com.ziiwee.reduce.describe.types.impls.PageTypeProvider;
import org.springframework.core.ResolvableType;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author ziiwee
 * @data 2020/8/12
 */
public class RestFindAllHandlerDescribeCreator extends AbstractRestHandlerCreator {

    private final Class<?> entityClass;
    private final String basePattern;

    public RestFindAllHandlerDescribeCreator(Class<?> entityClass, String basePattern) {
        this.entityClass = entityClass;
        this.basePattern = basePattern;
    }

    @Override
    public ResourceMethod getResourceMethod() {
        return ResourceMethod.FIND_ALL;
    }

    @Override
    public Class<?> getEntityClass() {
        return entityClass;
    }

    @Override
    public String getBasePattern() {
        return basePattern;
    }

    @Override
    public ResolvableType getType() {
        return ResolvableType.forClassWithGenerics(Page.class,getEntityClass());
    }

    @Override
    public Map<HttpRequestParameterType, List<FieldDescribe>> getParameters() {
        FieldDescribe pageable = new FieldDescribeModel("pageable", ResolvableType.forClass(Pageable.class), "分页信息", "", true, true, true, null, null);
        FieldDescribe condition = new FieldDescribeModel("condition", ResolvableType.forClass(String.class), "条件信息", "", true, true, true, null, null);
        Map<HttpRequestParameterType, List<FieldDescribe>> map = new HashMap<>();
        map.put(HttpRequestParameterType.QUERY, Arrays.asList(pageable, condition));
        return map;
    }
}
